using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
public partial class asp_pages_PetManager : System.Web.UI.Page
{

    ProductDAO daoPro = new ProductDAO();
    public void LoadInitData()
    {
        if (!IsPostBack)
        {

            PetCategoryDAO daoPetCate = new PetCategoryDAO();
            ProductCategoryDAO dapPrdCate = new ProductCategoryDAO();
            cmbPetCategories.DataSource = daoPetCate.GetAllCategories();
            cmbPetCategories.DataTextField = "Name";
            cmbPetCategories.DataValueField = "ID";
            cmbPetCategories.DataBind();
            cmbCategories.DataSource = dapPrdCate.GetAll();
            cmbCategories.DataTextField = "Name";
            cmbCategories.DataValueField = "ID";
            cmbCategories.DataBind();
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        LoadInitData();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        lblPreviewContent.Text = fckEditor.Value;
    }
    protected void lnkEditInfor_Click(object sender, EventArgs e)
    {

    }
    protected void Button3_Click(object sender, EventArgs e)
    {

    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Validate();
        if (!IsValid) return;
        if (fupImageURL.FileContent.Length > 2000000) { return; }
        String path=ConfigurationManager.AppSettings["image_path"];
        Product pro = new Product();

        pro.Name = txtName.Text;
        pro.Size = txtSize.Text;
        pro.Unit = txtUnit.Text;
        pro.Quantity =int.Parse( txtQuantity.Text);
        pro.Price = decimal.Parse(txtPrice.Text);
        pro.Category.ID = int.Parse(cmbCategories.SelectedValue);
        pro.ForCategoryOfPet.ID = int.Parse(cmbPetCategories.SelectedValue);
        pro.ImageURL =path+ fupImageURL.FileName;
        pro.TypeID = 0;
        pro.Information = fckEditor.Value;
        pro.ModifiedDate = DateTime.Now;
        if (daoPro.InsertProduct(pro) > 0)
        {
            fupImageURL.SaveAs(Server.MapPath(pro.ImageURL));
            lblMessage.Text = "New product has been added successfully";
        }
        else
        {
            lblMessage.Text = "Sorry. Error has occured and the information is not added to database.";
        }
    }
    protected void btnPrevInPage_Click(object sender, EventArgs e)
    {
       
    }
}
